﻿using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public  class dal_InsertColorBallAwardData
    {
        public string InsertColorBallAwardData(ResultClass model)
        {
            int[] r=new int[2];
            
            r[0] = 0;
            r[1] = 0;
            
            try
            {
                string sql = @"usp_Insert_ColorBallResult @id,@Name,@Code,@DetailsLink,@VideoLink,@AwardDate,@AwardWeek," +
                                        "@Red,@Red1,@Red2,@Red3,@Red4,@Red5,@Red6,@Blue,@Blue2,@Sales,@PoolMoney,@ContentArea," +
                                        "@addmoney,@addmoney2,@msg,@z2add,@m2add,@PrizeGradesID";
                SqlParameter[] pms = new SqlParameter[] {
                    new SqlParameter("@id",SqlDbType.UniqueIdentifier){ Value=model.id},
                    new SqlParameter("@Name",SqlDbType.NVarChar,50){ Value=model.Name},
                    new SqlParameter("@Code",SqlDbType.NVarChar,50){ Value=model.Code},
                    new SqlParameter("@DetailsLink",SqlDbType.NVarChar,50){ Value=model.DetailsLink},
                    new SqlParameter("@VideoLink",SqlDbType.NVarChar,50){ Value=model.DetailsLink },
                    new SqlParameter("@AwardDate",SqlDbType.NVarChar,50){ Value=model.AwardDate},
                    new SqlParameter("@AwardWeek",SqlDbType.NVarChar,50){ Value = model.AwardWeek},
                    new SqlParameter("@Red",SqlDbType.NVarChar,50){ Value=model.Red},
                    new SqlParameter("@Red1",SqlDbType.Int){ Value = model.Red1},
                    new SqlParameter("@Red2",SqlDbType.Int){ Value = model.Red2},
                    new SqlParameter("@Red3",SqlDbType.Int){ Value = model.Red3},
                    new SqlParameter("@Red4",SqlDbType.Int){ Value = model.Red4},
                    new SqlParameter("@Red5",SqlDbType.Int){ Value = model.Red5},
                    new SqlParameter("@Red6",SqlDbType.Int){ Value = model.Red6},
                    new SqlParameter("@Blue",SqlDbType.Int){ Value=model.Blue},
                    new SqlParameter("@Blue2",SqlDbType.Int){ Value = model.Blue2},
                    new SqlParameter("@Sales",SqlDbType.NVarChar,50){ Value=model.Sales},
                    new SqlParameter("@PoolMoney",SqlDbType.NVarChar,50)  { Value = model.PoolMoney},
                    new SqlParameter ("@ContentArea",SqlDbType.NVarChar,500){ Value=model.ContentArea},
                    new SqlParameter("@addmoney",SqlDbType.NVarChar,50){ Value=model.AddMoney},
                    new SqlParameter("@addmoney2",SqlDbType.NVarChar,50){ Value=model.AddMoney2},
                    new SqlParameter("@msg",SqlDbType.NVarChar,500){ Value = model.Msg},
                    new SqlParameter("@z2add",SqlDbType.NVarChar,50){ Value=model.Z2Add},
                    new SqlParameter ("@m2add",SqlDbType.NVarChar,50){ Value=model.M2Add},
                    new SqlParameter("@PrizeGradesID",SqlDbType.UniqueIdentifier){ Value=model.PrizeGradeID}
                };

                foreach (var item in model.PrizeGrades)
                {
                    //string sql1 = "insert into PrizeGrades(id,typelevel,typenum,typemoney)values(@id,@typelevel,@typenum,@typemoney)";
                    string sql1 = @"usp_Insert_PrizeGrades @id,@typelevel,@typenum,@typemoney";
                    SqlParameter[] pms1 = new SqlParameter[] {
                        new SqlParameter("@id",SqlDbType.UniqueIdentifier){ Value=model.id},
                        new SqlParameter("@typelevel",SqlDbType.Int){ Value=item.TypeLevel},
                        new SqlParameter("@typenum",SqlDbType.Int){ Value=item.TypeNum},
                        new SqlParameter("@typemoney",SqlDbType.NVarChar,50){ Value=item.TypeMoney}
                        };
                    r[0]+= SqlHelper.ExecuteNonQurey(sql1, CommandType.StoredProcedure, pms1);

                }
                r[1] += SqlHelper.ExecuteNonQurey(sql, CommandType.StoredProcedure, pms);
            }
            catch (Exception err)
            {
                return err.ToString();
            }
            return r.ToString();
        }
    }
}
